package com.gitee.openviducn.inspector.domain.vo.response.openvidu;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.gitee.openviducn.inspector.domain.vo.response.BaseResponse;
import io.openvidu.java.client.Recording;
import io.openvidu.java.client.RecordingLayout;
import io.swagger.annotations.ApiModel;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;

/**
 * @Author: https://gitee.com/wesleyOne
 * @Date: 03.04 2020
 */
@ApiModel(value = "Recording信息")
@Getter
@Setter
public class RecordingVO extends BaseResponse {

    private static final long serialVersionUID = 6661101764332012127L;

    private String status;
    private String id;
    private String sessionId;
    @JSONField(format="yyyy-MM-dd HH:mm:ss")
    private Date createdAt;
    /**
     * bytes
     */
    private Long size;
    /**
     * seconds
     */
    private Double duration;
    private String url;

    /**
     * RecordingProperties
     */
    private String name;
    private Recording.OutputMode outputMode;
    private RecordingLayout recordingLayout;
    private String customLayout;
    private String resolution;
    private Boolean hasAudio;
    private Boolean hasVideo;

    public static RecordingVO build(Recording recording) {
        RecordingVO vo = new RecordingVO();
        vo.setId(recording.getId());
        vo.setSessionId(recording.getSessionId());
        vo.setCreatedAt(new Date(recording.getCreatedAt()));
        vo.setSize(recording.getSize());
        vo.setDuration(recording.getDuration());
        vo.setUrl(recording.getUrl());
        vo.setStatus(recording.getStatus().name());
        vo.setName(recording.getName());
        vo.setOutputMode(recording.getOutputMode());
        vo.setRecordingLayout(recording.getRecordingLayout());
        vo.setCustomLayout(recording.getCustomLayout());
        vo.setResolution(recording.getResolution());
        vo.setHasAudio(recording.hasAudio());
        vo.setHasVideo(recording.hasVideo());
        return vo;
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}
